"""
    property 练习
        从 age = property(get, set) 方式升级成装饰器功能，达到一样的功能！
"""


class Enemy:
    def __init__(self, name, hp, weight):
      self.name = name
      self.hp = hp
      self.weight = weight
      
    @property
    def hp(self):
        """
            只读, property 只读装饰器
        """
        return self.__hp
    @hp.setter
    def hp(self, value):
        """写 .setter 写入装饰器
        """
        if 10 <= value <= 100:
            self.__hp = value
        else:
            print("超出！")

    @property
    def weight(self):
        return self.__weight
    @weight.setter
    def weight(self, value):
        if 40 <= value <= 80:
            self.__weight = value
        else:
            print("超出！")

lo = Enemy("小红", 20, 40)
lo.hp = 1000 
print(lo.hp)


